package config

import "time"

type Config struct {
	// 应用配置
	App struct {
		Mode        string
		Port        string
		Url         string
		Name        string
		Keywords    string
		Description string
		Version     string
		Author      struct {
			QQ    string `mapstructure:"qq"`
			Email string
		}
		// 是否是示例程序，如控制表单、表格数据操作事件阻止进一步操作等
		IsDemo bool `mapstructure:"is_demo"`
		Admin  struct {
			UseDemo        bool `mapstructure:"use_demo"`
			Entrance       string
			DashboardUrl   string   `mapstructure:"dashboard_url"`
			FileUploadUrl  string   `mapstructure:"file_upload_url"`
			StyleFileList  []string `mapstructure:"style_file_list"`
			ScriptFileList []string `mapstructure:"script_file_list"`
		}
	}
	// 数据库配置
	Database struct {
		Type            string
		Host            string
		Port            string
		User            string
		Password        string
		Name            string
		TablePrefix     string `mapstructure:"table_prefix"`
		ConnMaxLifetime int    `mapstructure:"conn_max_lifetime"`
		ConnMaxIdleTime int    `mapstructure:"conn_max_idle_time"`
		MaxIdleConns    int    `mapstructure:"max_idle_conns"`
		MaxOpenConns    int    `mapstructure:"max_open_conns"`
	}
	// Redis配置
	Redis struct {
		Host        string
		Port        string
		DB          int `mapstructure:"db"`
		Password    string
		Prefix      string
		MaxIdle     int           `mapstructure:"max_idle"`
		MaxActive   int           `mapstructure:"max_active"`
		IdleTimeout time.Duration `mapstructure:"idle_timeout"`
	}
	// 默认值
	Default struct {
		Article struct {
			Cover string
		}
		Category struct {
			Pid        uint64
			Name       string
			Alias      string
			Img        string
			LevelLimit int `mapstructure:"level_limit"`
		}
	}
	// 百度站点地图
	Baidu struct {
		SiteMapSite  string `mapstructure:"site_map_site"`
		SiteMapToken string `mapstructure:"site_map_token"`
	}
	// elasticsearch
	Elasticsearch struct {
		Enable      bool     `mapstructure:"enable"`
		IndexPrefix string   `mapstructure:"index_prefix"`
		Hosts       []string `mapstructure:"hosts"`
	}
}

// 获取后台安全入口，默认为"/admin"
func (c *Config) GetAppAdminEntrance() string {
	entrance := c.App.Admin.Entrance
	if entrance == "" {
		entrance = "/admin"
	}
	return entrance
}
